import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// Comment out direct env variable assignment as it doesn't work on Windows
// process.env.SASS_SILENCE_DEPRECATION_WARNINGS = 'true';

const isDev = process.env.NODE_ENV === 'development'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    port: 3000,
    proxy: isDev
      ? {
          '/api': {
            target: 'http://localhost:5000',
            changeOrigin: true,
            rewrite: (path) => path
          },
          '/ws': {
            target: 'ws://localhost:5000',
            ws: true
          }
        }
      : undefined
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `$env: '${process.env.NODE_ENV}';`,
        sassOptions: {
          outputStyle: 'expanded',
          charset: false
        }
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: ['vue', 'vue-router', 'pinia']
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ]
})